package com.ifish.leetcode.problem.algorithm;

import com.ifish.leetcode.problem.BaseLeetCodeProblem;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by iFish on 2017/7/8.
 */

public class _0001 extends BaseLeetCodeProblem {

    @Override
    public String title() {
        return "Two Sum";
    }

    @Override
    public void run() {
        super.run();
        int []result = addNums(new int []{3,2,4}, 6);
    }

    public int[] addNums(int[] nums, int target) {
        int[] result = new int[2];
        Map<Integer, Integer> map = new HashMap();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i])) {
                result[0] = map.get(target - nums[i]);
                result[1] = i;
            }
            map.put(nums[i], i);
        }
        return result;
    }
}
